package com.example.filedialoglib;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;

import com.ys.filelib.filedialog.FileType;
import com.ys.filelib.filedialog.ProgressView;
import com.ys.filelib.filedialog.StorageDialog;
import com.ys.filelib.filedialog.StorageItem;
import com.ys.filelib.filedialog.TipProgressDialog;
import com.ys.filelib.filedialog.config.FileSelectConfig;
import com.ys.filelib.filedialog.ftp.FTPHelper;
import com.ys.filelib.filedialog.loader.RemoteDiskDao;
import com.ys.filelib.filedialog.util.MyLog;

import java.io.File;
import java.util.List;

public class MainActivity extends Activity {

    int num = 69;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        StorageDialog storageDialog = new StorageDialog(MainActivity.this);
        storageDialog.setSelectMode(FileSelectConfig.MODEL_SELECT_MORE);
        storageDialog.setOnSelectFileListener(new StorageDialog.OnSelectFileListener() {
            @Override
            public void onSelect(File file, int fileType) {
                MyLog.cdl("==文件选择=单选=" + file);
            }

            @Override
            public void onSelectBackList(List<String> fileList) {
                MyLog.cdl("==文件选择=多选=" + fileList);
            }
        });

        findViewById(R.id.btn_gress).setOnClickListener(v -> {
            //new TipProgressDialog(this).show();
            //new ProgressView(this).show();
            /*FTPHelper helper = FTPHelper.create("192.168.3." + num, 21, "admin", "admin");
            RemoteDiskDao.DriveUser user = RemoteDiskDao.create(helper);
            user.path = "/";
            RemoteDiskDao.insertDriveUser(getApplication(), user);
            num++;*/
        });
        findViewById(R.id.btn_image).setOnClickListener(v -> {
            storageDialog.setFileType(FileType.FILE_IMAGE);
            storageDialog.show();
        });
        findViewById(R.id.btn_audio).setOnClickListener(v -> {
            storageDialog.setFileType(FileType.FILE_AUDIO);
            storageDialog.show();
        });
        findViewById(R.id.btn_video).setOnClickListener(v -> {
            storageDialog.setFileType(FileType.FILE_VIDEO);
            storageDialog.show();
        });
        findViewById(R.id.btn_office).setOnClickListener(v -> {
            storageDialog.setFileType(FileType.FILE_OFFICE);
            storageDialog.show();
        });
        findViewById(R.id.btn_mult).setOnClickListener(v -> {
            storageDialog.addFileType(FileType.FILE_IMAGE);
            storageDialog.addFileType(FileType.FILE_AUDIO);
            storageDialog.addFileType(FileType.FILE_VIDEO);
            storageDialog.addFileType(FileType.FILE_OFFICE);
            storageDialog.show();
        });

    }

    @Override
    protected void onStart() {
        super.onStart();
        if (Build.VERSION.SDK_INT > 29) {
            if (!Environment.isExternalStorageManager()) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                intent.setData(Uri.parse("package:" + getPackageName()));
                startActivity(intent);
            }
        }
    }
}